//
//  NewTutorialViewController2.m
//  TutorialsModule
//
//  Created by Augusto Guido on 08/10/09.
//  Copyright 2009 Moove-IT. All rights reserved.
//

#import "NewTutorialViewController2.h"
#import "NewStepViewController.h"
#import "NewStepViewController2.h"
#import "NewTitleAndDescription.h"
#import "NewDescriptionController.h"
#import "NewTagViewController.h"
#import "SelectVideoTableViewController.h"
#import "StepsTableViewController.h"

@implementation NewTutorialViewController2

@synthesize myHeaderView;
@synthesize mySegmentedControl;
@synthesize stepsTable;

- (IBAction)changeType:(id)sender {
    
}

/*
- (id)initWithStyle:(UITableViewStyle)style {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    if (self = [super initWithStyle:style]) {
    }
    return self;
}
*/

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {        
		[self setHidesBottomBarWhenPushed: YES];
		self.title = @"New Tutorial";
    }
    return self;
}


- (void)viewDidLoad {
	// set up the table's header view based on our UIView 'myHeaderView' outlet
	
	UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save)];
	UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(pop)];
	
	self.navigationItem.rightBarButtonItem = done;
	self.navigationItem.leftBarButtonItem = cancel;
	
	[done release];
	[cancel release];
	
	CGRect newFrame = CGRectMake(0.0, 0.0, self.tableView.bounds.size.width, self.myHeaderView.frame.size.height);
	self.myHeaderView.backgroundColor = [UIColor clearColor];
	self.myHeaderView.frame = newFrame;
	self.stepsTable.tableHeaderView = self.myHeaderView;	// note this will override UITableView's 'sectionHeaderHeight' property
	self.stepsTable.editing = YES;
	self.stepsTable.allowsSelectionDuringEditing = YES;	
	
    [super viewDidLoad];

}


/*
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
	[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
	[super viewDidDisappear:animated];
}
*/

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
 //   return (interfaceOrientation == UIInterfaceOrientationPortrait);
	return YES;
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
	if (section == 0) 
		return @"Tutorial Information";	
	else 
		return @"";
}



#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
	return 2;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return 1;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *kCellID = @"cellID";
	
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
	if (cell == nil)
	{
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID] autorelease];
		cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
		cell.selectionStyle = UITableViewCellSelectionStyleBlue;
	}
	if (indexPath.section == 0)
		cell.textLabel.text = @"Add description";
	else cell.textLabel.text = @"Add tags";
	
	return cell;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
	return UITableViewCellEditingStyleInsert;
}

- (IBAction)addTitleAndDescription {
    NewTitleAndDescription *titleAndDesc = [[NewTitleAndDescription alloc] initWithNibName:@"NewTitleAndDescription" bundle:nil];
	[self.navigationController pushViewController:titleAndDesc animated:YES];
	[titleAndDesc release];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0){		
		NewDescriptionController *next = [[NewDescriptionController alloc] initWithNibName:@"NewDescriptionController" bundle:nil];			
		[self.navigationController pushViewController:next animated:YES];
		[next release];
	}
	else{
		NewTagViewController *next = [[NewTagViewController alloc] initWithNibName:@"NewTagViewController" bundle:nil];			
		[self.navigationController pushViewController:next animated:YES];
		[next release];
	}	
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/
- (void)pop{
	[self.navigationController popViewControllerAnimated:YES];
}

- (void)save{
	StepsTableViewController *stepsViewController = [[StepsTableViewController alloc] initWithNibName:@"StepsTableViewController" bundle:nil];
	stepsViewController.new = YES;
	[self.navigationController pushViewController:stepsViewController animated:YES];
	[stepsViewController release];
}

- (void)dealloc {
    [super dealloc];
}


@end

